app.controller('sys_configController', ['$scope', 'httpWrapService', '$state', '$stateParams','uiGridConstants','GridFactory',
        function($scope, httpWrapService, $state, $stateParams,uiGridConstants, GridFactory) {

    var columnDefs = [
        {name: "类型", field: "type",
            filter : {
                type :  uiGridConstants.filter.CONTAINS
            }
        },
        {name: "标签", field: "label",
            filter : {
                type :  uiGridConstants.filter.CONTAINS
            }} ,
        {name: "值", field: "value",
            filter : {
                type :  uiGridConstants.filter.CONTAINS
            }} ,
        {name: "顺序", field: "sort", enableFiltering : false,enableSorting: false},
        {name: "描述", field: "description",enableSorting: false,
            filter : {
                type :  uiGridConstants.filter.CONTAINS
            }} ,
        {
            displayName: "",
            field: "id",
            enableFiltering: false,
            enableSorting: false,
            maxWidth: 90,
            cellTemplate: '<button class="btn btn-default m-b-xs w-xs" ng-click="grid.appScope.view(this)">查看/编辑</button>'
        } //,
        //{
        //    displayName: "",
        //    field: "id",
        //    enableFiltering: false,
        //    enableSorting: false,
        //    maxWidth: 90,
        //    cellTemplate: '<button class="btn btn-danger m-b-xs w-xs" ng-disabled="grid.appScope.Grid.deletes[\'{{COL_FIELD}}\']" ng-click="deleteBtnDisable[id] = true; grid.appScope.delete(this);">删除</button>'
        //}
    ];

    $scope.Grid = GridFactory.newInstance({
        url : 'system/config/list.do',
        columnDefs : columnDefs,
        gridOptions : {
            useExternalSorting : true,
            useExternalPagination : true,
            useExternalFiltering : true
        }
    });
    $scope.Grid.load();

    $scope.add = function() {
        $state.go('app.system.config.view', {type : "add"});
    };
    $scope.view = function(target) {
        $state.go('app.system.config.view', {id : target.$parent.row.entity.id, type:"update" });
    };

    $scope.delete = function(target) {
        var id = target.$parent.row.entity.id;
        httpWrapService.defaultGridDelete($scope.Grid, id,'system/config/delete/'+ id +'.do').then(function(res){
            $scope.Grid.deleteRow(target.$parent.row.entity);
        });
    };

}]);